<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>遍历parents()</title>
    <script src="../jquery-3.4.1.js"></script>
    <style>
        .left {
            width: auto;
            height: 400px;
        }

        .left div {
            width: 350px;
            height: 150px;
            padding: 5px;
            margin: 5px;
            float: left;
            background: #bbffaa;
            border: 1px solid #ccc;
        }

        span {
            color: blue;
        }
    </style>
</head>
<body>
    <h2>parents方法()</h2>
    <div class="left first-div">
        <div class="div">
            <ul class="level-2">
                <!-- A -->
                <li class="item-a">A</li>
                <!-- B -->
                <li class="item-b">B
                    <ul class="level-3">
                        <li class="item-1">1</li>
                        <li class="item-2">2</li>
                        <li class="item-3">3</li>
                    </ul>
                </li>
                <!-- C -->
                <li class="item-c">C</li>
            </ul>
        </div>
        <div class="div">
            <ul class="level-2">
                <!-- A -->
                <li class="item-a">A</li>
                <!-- B -->
                <li class="item-b">B
                    <ul class="level-3">
                        <li class="item-1">1</li>
                        <li class="item-2">2</li>
                        <li class="item-3">3</li>
                    </ul>
                </li>
                <!-- C -->
                <li class="item-c">C</li>
            </ul>
        </div>
    </div>
    <button>parent无参数</button>
    <button>parent传递选择器</button>
</body>
<script>
    $("button:first").click(function () {
        $('.item-b').parents().css('border','2px solid red')
    });
    $("button:last").click(function () {
        $('.item-b').parents('.first-div').css('border','2px solid blue')
    })
</script>
</html>